<?php
require_once APPLICATION_PATH.'\misc\sessionController.php';

class ActivationController extends Zend_Controller_Action
{

    public function init()
    {$this->_helper->layout->disableLayout();
        /* Initialize action controller here */
    }

    public function indexAction()
    {           $this->_helper->layout->disableLayout();
        $sessionController=new sessionController();
        $this->view->sessioncontroller = $sessionController;
        $this->view->transactions = new Application_Model_DbTable_Transaction();
        /* Initialize action controller here */

        // action body
        $sessionController = new sessionController();
        $cat_db = new Application_Model_DbTable_Category();
        $this->view-> categories = $cat_db->fetchAll();
        if($sessionController->checkSessionBuyer()){
            $this->view->contentcontroller='FrontPage';
            $this->view->contentaction='afterlogin';
            $sessionController->setBuyer();
            $this->view->buyerId=$sessionController->getSessionId();
            $this->view->rightlabel = "Pembeli";
        }else{
            $this->view->contentcontroller='buyer';
            $this->view->contentaction='login';
            $this->view->buyerId=0;
            $this->view->rightlabel = "Login Pembeli";
        }
        $this->view->transaction = new Application_Model_DbTable_Transaction();
        $this->_helper->layout->setLayout('frontlayout');
        
       
        if(!isset($_GET['code'])){
            //Action if there no code
            $this->_helper->redirector('index','FrontPage');
        }else{
            $code=$_GET['code'];
            $activation = new Application_Model_DbTable_Activation();
            $buyer = new Application_Model_DbTable_Buyers();
            $username=$activation->getUsername($code);
                if($username == NULL || $username == ""){
                    //Action if the code is not valid
                    $this->_helper->redirector('index','FrontPage');

                }else{
                    $buyer->updateBuyerStatus(1, $username);//update buyer status
                    $activation->deleteActivation($code);//delete activation code
                    
                }

    }
    }

    public function activateAction()
    {            $this->_helper->layout->disableLayout();
        $sessionController=new sessionController();
        $this->view->sessioncontroller = $sessionController;
        $this->view->transactions = new Application_Model_DbTable_Transaction();
        /* Initialize action controller here */

        // action body
        $sessionController = new sessionController();
        $cat_db = new Application_Model_DbTable_Category();
        $this->view-> categories = $cat_db->fetchAll();
        if($sessionController->checkSessionBuyer()){
            $this->view->contentcontroller='FrontPage';
            $this->view->contentaction='afterlogin';
            $sessionController->setBuyer();
            $this->view->buyerId=$sessionController->getSessionId();
            $this->view->rightlabel = "Pembeli";
        }else{
            $this->view->contentcontroller='buyer';
            $this->view->contentaction='login';
            $this->view->buyerId=0;
            $this->view->rightlabel = "Login Pembeli";
        }
        $this->view->transaction = new Application_Model_DbTable_Transaction();
        $this->_helper->layout->setLayout('frontlayout');
       
        
        if(!isset($_GET['code'])){
            //Action if there no code
            $this->_helper->redirector('index','FrontPage');
        }else{
            $code=$_GET['code'];
            $activation = new Application_Model_DbTable_Activation();
            $buyer = new Application_Model_DbTable_Buyers();
            $username=$activation->getUsername($code);
                if($username == NULL || $username == ""){
                    //Action if the code is not valid
                    $this->_helper->redirector('index','FrontPage');

                }else{
                    $buyer->updateBuyerStatus(1, $username);//update buyer status
                    $activation->deleteActivation($code);//delete activation code

                }

    }
    }
    public function listAction()
    {
        // action body
    }


}





